package main

import "fmt"

func f0(x int, y int) (ret int) {
	ret = x + y
	return
}

func test() (int, int) {
	return 1, 2
}

// 具名返回参数
func test2() (a int, b int) {
	a, b = 3, 5
	return
}

// 不定长参数
func f1(args ...int) {
	fmt.Printf("args is %T \n", args)
}
func f2(args ...int) {
	f1(args...)
}

// 参数类型一样，可以省略前面的类型
func f3(x, y int, a, b string) int {
	return x + y
}

func f4(x, y, z int) int {
	return x + y + z
}

func f5() {
	fmt.Print("A")
	defer fmt.Print("B")
	defer fmt.Print("C")
	fmt.Print("D")
}

func f6(x int, y int) (ret int) {
	ret = x + y
	fmt.Printf("x=%d, y=%d, ret=%d\n", x, y, ret)
	return
}
func f7() {
	fmt.Println("A")
	defer f6(f6(1, 2), f6(3, 4))
	fmt.Println("B")
}

func main() {
	fmt.Println(test())
	fmt.Println(test2())
	f1(1, 2, 3)
	f2(1, 2, 3)
	fmt.Println(f0(3, 5))               // 8
	fmt.Println(f3(3, 5, "aaa", "bbb")) // 8
	// var arr = []int{3, 5, 7}
	// fmt.Println(f4(arr...))
	/*
		not enough arguments in call to f4
		have ([]int...)
		want (int, int, int)
	*/
	f5()
	fmt.Println("--------------")
	f7()
	/*
		A
		x=1, y=2, ret=3
		x=3, y=4, ret=7
		B
		x=3, y=7, ret=10
	*/

}
